/**
 *  @author phi
 *  @memo   
 */

#pragma once

#include <iostream>
#include <cstdlib>
#include "events/event.hpp"

using namespace std;

namespace tmlib {


    class EventDispatcher
    {
    public :
        typedef bool (*EventFunc)(events::Event*);

    public :
        EventDispatcher()
        {
            memset(_eventFunctorList, 0, sizeof(_eventFunctorList));
            _event = new events::Event();
            _event->setTarget(this);
        }
        virtual ~EventDispatcher()
        {
            if (_event) { delete _event; _event = NULL; }
        }

        void dispatchEvent(events::EventInfo::EventType type)
        {
            if (_eventFunctorList[type]) {
                _event->setType(type);
                _eventFunctorList[type](_event);
            }
        }

        void addEventListener(events::EventInfo::EventType type, EventFunc func)
        {
            _eventFunctorList[type] = func;
        }

    private :
        events::Event*  _event;
        EventFunc       _eventFunctorList[events::EventInfo::EVENT_TYPE_MAX];
    };


}